import { EChartsOption } from 'echarts'
import { EChartsProps } from 'type'
import { PieTransformedProps } from 'type/pie'

function echartOptions(transformProps: PieTransformedProps): EChartsProps {
  const { width, height, formData, showBackground, label } = transformProps
  const echartOptions: EChartsOption = {
    series: {
      type: 'bar',
      data: Object.values(formData),
      showBackground,
      label: label ? {
        show: true,
        ...label,
        formatter: label?.formatter.join('\n'),
      } : undefined
    },
    grid: {
      left: 0,
      right: 0,
      top: 0,
      bottom: 0,
      width: '100%',
      containLabel: false,
    },
    xAxis: {
      data: Object.keys(formData),
    },
    yAxis: {},
  }

  return {
    width,
    height,
    echartOptions,
  }
}

export default echartOptions